package com.falcon.service.impl;

import com.falcon.service.IVbenGeneratorService;
import com.falcon.generator.vben.ITsTypeGenerator;
import com.falcon.generator.vben.impl.TsApiCodeGenerator;
import com.swan.core.utils.ClassUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/** vben 代码生成器
 * @author zongf
 * @date 2024-02-18
 **/
@Slf4j
@Service
public class VbenGeneratorService implements IVbenGeneratorService {

    @Autowired
    private TsApiCodeGenerator tsApiCodeGenerator;

    @Autowired
    private ITsTypeGenerator tsTypeGenerator;

    @Override
    public void generateApiTs(Class controllerClz) {
        this.tsApiCodeGenerator.generateCode(controllerClz);
    }

    @Override
    public void generateDomain(String canonicalName) {

        Class clz = ClassUtil.forName(canonicalName, this.getClass().getClassLoader());

        this.tsTypeGenerator.generateCode(clz);
    }

}
